package de.jkoslows.ui.actions;

import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeListener;

import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class CloseWindow implements Action {

	private static final String ACTION_NAME = "Beenden";
	private static final String CLOSE_MESSAGE = "Soll die Anwendung beendet werden?";
	private static final String CLOSE_COMMAND = "CLOSE";
	private JFrame mainWindow;
	private boolean isEnabled = true;

	public CloseWindow(JFrame window) {
		this.mainWindow = window;
		window.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				actionPerformed(new ActionEvent(e.getSource(), e.getID(),
						CLOSE_COMMAND));
			}
		});
	}

	public void actionPerformed(ActionEvent e) {
		int showConfirmDialog = JOptionPane.showConfirmDialog(mainWindow,
				CLOSE_MESSAGE);
		if (JOptionPane.OK_OPTION == showConfirmDialog)
		{
			mainWindow.dispose();
		}

	}

	public Object getValue(String key) {
		/*
		 * get key MnemonicKeyget key Nameget key ShortDescriptionget key
		 * SmallIconget key ActionCommandKeyget key SwingSelectedKeyget key
		 * SwingDisplayedMnemonicIndexKeyget key AcceleratorKey
		 */
		if (Action.NAME.equals(key)) {
			return ACTION_NAME;
		}
		if (Action.SMALL_ICON.equals(key)) {
			return null;
		}
		if (Action.SHORT_DESCRIPTION.equals(key)) {
			return null;
		}
		return null;
	}

	public void putValue(String key, Object value) {
		// TODO Auto-generated method stub

	}

	public void setEnabled(boolean b) {
		this.isEnabled = b;

	}

	public boolean isEnabled() {
		return isEnabled;
	}

	public void addPropertyChangeListener(PropertyChangeListener listener) {
		// TODO Auto-generated method stub

	}

	public void removePropertyChangeListener(PropertyChangeListener listener) {
		// TODO Auto-generated method stub

	}

}
